package com.alipay.api.internal.util.json;

import com.alipay.api.internal.util.json.JSONErrorListener;
import com.alipay.api.internal.util.json.JSONReader;
import com.alipay.api.internal.util.json.JSONValidator;
import com.alipay.api.internal.util.json.StdoutStreamErrorListener;

public class JSONValidatingReader extends JSONReader {

   public static final Object INVALID = new Object();
   private JSONValidator validator;


   public JSONValidatingReader(JSONValidator validator) {
      this.validator = validator;
   }

   public JSONValidatingReader(JSONErrorListener listener) {
      this(new JSONValidator(listener));
   }

   public JSONValidatingReader() {
      this((JSONErrorListener)(new StdoutStreamErrorListener()));
   }

   public Object read(String string) {
      return !this.validator.validate(string)?INVALID:super.read(string);
   }

}
